package demo03;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class work03 {
	public void main(String[] args) throws IOException {
		
		
		File srcFile=new File("d:\\Users\\lcl\\Desktop\\aaa");
		File desFile=new File("d:\\Users\\lcl\\Desktop\\copy");
		
		copyFile(srcFile,desFile);
	}

	public void copyFile(File srcFile,File desFile) throws IOException{
		FileInputStream fis=new FileInputStream(srcFile);
		FileOutputStream fos=new FileOutputStream(desFile);
		
		if(srcFile.isFile()){
			byte[] buf=new byte[1024];
			 int len=0;
			 while((len=fis.read(buf))!=-1){
				 fos.write(buf,0,len);
			 }
			
		}else{
			File[] files=srcFile.listFiles();
			for (int i = 0; i < files.length; i++) {
				copyFile(files[i],desFile);
			}
		}
	}
}
